package com.chen.cloudpicture.api.imageSearch;

import com.chen.cloudpicture.api.imageSearch.model.ImageSearchResult;
import com.chen.cloudpicture.api.imageSearch.sub.GetImageFirstUrlApi;
import com.chen.cloudpicture.api.imageSearch.sub.GetImageListApi;
import com.chen.cloudpicture.api.imageSearch.sub.GetImagePageUrlApi;
import lombok.extern.slf4j.Slf4j;

import java.util.List;

/**
 * 设计模式：门面模式
 * 当一个业务需要调用多个接口时，可以写一个 api 封装所有接口的调用，这样外界就只需要调用这一个接口就能实现业务功能了。
 * <p>
 * 这样把所有功能都实现到了imageSearch包中，也实现了高内聚，低耦合
 */
@Slf4j
public class ImageSearchApiFacade {

    /**
     * 以图搜图，搜索图片
     */
    public static List<ImageSearchResult> searchImage(String imageUrl) {
        String imagePageUrl = GetImagePageUrlApi.getImagePageUrl(imageUrl);
        String imageFirstUrl = GetImageFirstUrlApi.getImageFirstUrl(imagePageUrl);
        List<ImageSearchResult> imageSearchResultList = GetImageListApi.getImageList(imageFirstUrl);
        return imageSearchResultList;
    }

    public static void main(String[] args) {
        List<ImageSearchResult> imageSearchResultList = searchImage("https://chen25480-1371220469.cos.ap-shanghai.myqcloud.com/public/1949877657653256193/public/1949877657653256193_Ltuo8WkwaGf8mul6_thumbnail.jpg");
        System.out.println("结果列表" + imageSearchResultList);
    }
}
